package control.panel
{
	import global.GameState;
	
	import model.load.XmlLoadMessage;
	
	import view.panel.VipSetPanel;

	public class VipSetPanelControl extends PanelControl
	{
		private var currentSetType:int;
		
		public function VipSetPanelControl()
		{
			initPanel();
		}
		
		private function initPanel():void
		{
			_view.vipSetPanel = new VipSetPanel(this);
		}
		
		public function open():void
		{
			_view.vipSetPanel.selectYesNo(GameState.isShowVip);
			_view.vipSetPanel.updateDeadTime(GameState.vipTime);
			_view.vipSetPanel.open();
		}
		
		public function onVipSet(type:int):void
		{
			currentSetType = type;
			var msg:XmlLoadMessage = new XmlLoadMessage(onSetBack);
			msg.url = GameState.getServerLink() + "50&key=" + GameState.snsKey + "&value=" + type; 
			msg.send();
			_control.alertPanelControl.alert("设置VIP中，请稍等...");
			_view.vipSetPanel.close();
		}
		
		private function onSetBack(xml:XML,id:int):void
		{
			_control.alertPanelControl.close();
			var result:int = int(xml.@res);
			if (result == 1)
			{
				_control.alertButPanelControl.alert("设置成功!","");
				GameState.isShowVip = Boolean(currentSetType);
				
			}
			else
			{
				_control.alertButPanelControl.alert("设置失败。","");
			}
		}
		
	}
}